package com.qujia.web.controller.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.UUID;

/**
 * 随行付，公共方法
 */
public class SXFPaySign {
    //合作方私钥(替换成自己的)
    // public static final String privateKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDM+4PMi2ZPqpeCQ1IIV8mWYmGubr3DoEEJ3W2oEu8bFMVVpK5Jx6WhQ9xR83OQW7lbMI+BbumilKXfHdHrW7gWvu7yB2dD50GbT6bZXXnuddui+BnS/Yc9QxFS+HLcOX8bsmgJ5P/4D1Klm4k3OOsGJ3CsLDuz8RwNlxwuhg8+lQIDAQAB";
    //测试环境私钥
    //public static final String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMz7g8yLZk+ql4JDUghXyZZiYa5uvcOgQQndbagS7xsUxVWkrknHpaFD3FHzc5BbuVswj4Fu6aKUpd8d0etbuBa+7vIHZ0PnQZtPptldee5126L4GdL9hz1DEVL4ctw5fxuyaAnk//gPUqWbiTc46wYncKwsO7PxHA2XHC6GDz6VAgMBAAECgYEAgC2C1CQTPRvqk+0u3cKvbtdkR6Q+C5cpNFb/XAtC80dAwnYw+jfarYX2vlQi3pFMzeYGxqQpep3DP0qxWqBG8uu7Depw2HlWcw+6z68G3Vpkprx9FHnsy/ijCX/76HMmDmGN1r68FnDZXHKdaLZPQeNxDY3Hz83Quq04yav5Ah0CQQDoVoZZM6SyF+gz4/mg29UwkEXcn5uUARWo7QrO6vOsYzTEiNvNIlLFxd5xE2i9LAKKLWBtuaMovrdC4fHguQaLAkEA4dvINHcuehDHVzgS5I/6hB5PnQZOrnZFDZUd7woh9xUu9qQTxZpPcbfSpDFCKDbTknM1dn+7WpLk6Zd9YGyTXwJACXu2oh90gnxtUujkQIeYjRHmeBnfrMvaiXmbblSyu3+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tHb9W//zDTJAaiKEp6CYlZqjfZfbiZvdNFkADN3RvwblByT6WinveufjDB0NJ7GUkjcsa0fJe6iHnyHrzLfL/JYXL6Q5BR4gwKBgQDCI9iWlb6S0I0pYGFoopkIKEfK34v6V94SJmE36Et1Jw/OhW/mMDPm05SuOijWRwggYQbGhkM5nAlvurBWDLDNF0Q69J3liJ78kt6iu4byMXhSAbL82cdu3xRv7h1l5VW0RJmjY/s1fSwP+33R+v7vzYNA2oZug7br0+5X2UaGXQKBgAU40gV+yZ4tPY008CLjmvsKqrLk4LZVUyGUf9+U2y2CufyJQUtGQwWHfYWZVmJ867UO6SuVS8zAKi/6hpVYKcbbhWqh/LgHDTRS7y1sCv4Tg6W544T1cNByCycBNQkqLXOU/u8w/s6p2x2MJzZjwpylxDm8YazJCkJdLDdxbZVlAoGAO2x1c0JKnu2vB6c0qa57YP/TWcmrMumKU8vjnhVAY4+dSv2VDsRaXqEMtXef4FbFqgOI62NVWGDmkoh2SSCBTYV9oP4XBpcW8wCRnQYBfEigJ5nVi4etf8ZQnyInZXUZEqCc1mJYFjtGLW4xSQCm4Afr0QISe+ldKDoqjkE3URECgYBZchQGPb8PY/GMnYp9uM+osyhX8y02dXjRMFc01JwxUGWhp/WzRsDfjv2YSLm/ZfWkV3piLhEXPU6U8zp8Kp7butH1e8atjs9Vw2LqDYMHWFfBpIvLg1zvRNvS5smpkBIlhxupWUumLfgaSNGbYCbLpZ6z8qNgOrK3LV9kfHuBzg==";
    //随行付公钥
   // public static final String sxfPublic = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCOmsrFtFPTnEzfpJ/hDl5RODBxw4i9Ex3NmmG/N7A1+by032zZZgLLpdNh8y5otjFY0E37Nyr4FGKFRSSuDiTk8vfx3pv6ImS1Rxjjg4qdVHIfqhCeB0Z2ZPuBD3Gbj8hHFEtXZq8+msAFu/5ZQjiVhgs5WWBjh54LYWSum+d9+wIDAQAB";
   //生产环境随行付公钥
    public static final String sxfPublic = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo6QLP2QvCfqy9LwBV715kQo4GuKcyz+bf/E25kdwnkt4XmLcPWoROIMJJKncBPSexaCFE5HfTP9r95OmjuM0I7T4+Ns8Osl9F2iSaUxdjE2oCmfINUpPbSzhPrQ4232+ihV3uNuImumHEQuoD3bX2DKedPDx+/th8mCZ3jY6Lia7kHj4m4kEOIAqz+v4b8s0Bw1zuIeZFGzSAtIHH9DoA6l9laXEWb9Jqf3rv9mgujtamyVJCCSjzs0TM2qVBGAJrijfl6xok0ZBQVhdixlk3rClqnqldSIG5zMV1eiL4GW1TE2ddjkdU7gnMn9TCPODjUNf+yVVARmyXIhKkVZZlwIDAQAB";
    /**
     * 封装传参信息，增加公共信息，增加业务信息
     * @param reqData
     * @return
     */
    public static String getSXFPay(JSONObject reqData ) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String dataStr = df.format(new Date());
        ApiRequestBean<JSONObject> reqBean = new ApiRequestBean<JSONObject>();
        //reqBean.setOrgId("77563944");//测试 合作机构id
        reqBean.setOrgId("92346959");//生产合作机构id
        reqBean.setReqId(UUID.randomUUID().toString().replaceAll("-", ""));//请求id 订单号
        reqBean.setSignType("RSA");//签名类型
        reqBean.setTimestamp(dataStr);//请求时间
        reqBean.setVersion("1.0");//版本
        //将业务参数存放在 JSON 对象中
        reqBean.setReqData(reqData);
        String req = JSONObject.toJSONString(reqBean);
        System.out.println("req:" + req);
        return req;
    }


    /**
     *封装组织加密串
     */
    public static String getSignContent(String req){
        System.out.println("req:" + req);
        //此处不要改变reqData里面值的顺序用LinkedHashMap
        HashMap reqMap = JSON.parseObject(req, LinkedHashMap.class, Feature.OrderedField);
        //组装加密串
        String signContent = RSASignature.getOrderContent(reqMap);
        return "";
    }

}
